<template>
  <div>
    <myheader />
    <table>
      <tr>
        <td>名称</td>
        <td>图片</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in filelist">
        <td>{{ i.name }}</td>
        <td>
          <van-image round width="10rem" height="10rem" :src="i.url" />
        </td>
        <td><button @click="del(i.name)"> 删除</button>
        <button @click="downpic(i.name)">下载</button>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
import myheader from "./myheader.vue";
export default {
  data() {
    return {
      filelist: [],
      userid: localStorage.getItem("userid"),
    };
  },
  methods: {
    get_file() {
      this.$axios.get("/users/get_file?userid=" + this.userid)
    .then(res=>{
        this.filelist = res.data.list
    })
      ;
    },
    del(name){
        this.$axios.delete('/users/get_file?userid='+this.userid+'&name='+name)
        .then(res=>{
            if(res.data.code==200){
                alert('删除成功')
                this.get_file()
            }
        })
    },
    downpic(name){
      window.location.href='http://localhost:5000/users/downpic?userid='+this.userid+'&name='+name

    }
  },
  components: {
    'myheader': myheader,
  },
  mounted() {
    this.get_file();
  },
};
</script>

<style scoped>
</style>